<?php

namespace common\model;

use think\Hook;
use think\model\RelationModel;

class TaskClockModel extends RelationModel
{

    //自动验证
    protected $_validate = [
        ['task_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['time', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['created_by', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
    ];

    //自动完成
    protected $_auto = [
        ['created', 'time', self::MODEL_INSERT, 'function'],
    ];

    public function _after_insert($pk, $pkName, $data, $options)
    {
        parent::_after_insert($pk, $pkName, $data, $options);
        if(!empty($options['disable_db_after']) && $options['disable_db_after'] === true){
            // 禁用db后处理事件
            return;
        }

        $param = [
            'pk' => $pk,
            'pk_name' => $pkName,
            'data' => $data,
            'options' => $options,
        ];
        Hook::listen('after_task_clock_created', $param);
    }
}
